AS := x86_64-elf-as
LD := x86_64-elf-ld -m elf_x86_64
LDFLAG := -Ttext 0x0 -s --oformat binary

image: linux.img

linux.img: boot setup
	dd if=/dev/zero of=linux.img bs=1k count=1440
	dd if=boot of=$@ bs=512 count=1 conv=notrunc
	dd if=setup of=$@ bs=512 count=4 seek=1 conv=notrunc

boot: boot.o
	$(LD) $(LDFLAG) -o $@ boot.o

boot.o: boot.S
	$(AS) -o $@ $<

setup: setup.o
	$(LD) $(LDFLAG) -e _start_setup -o $@ $<

setup.o: setup.S
	$(AS) -o $@ $<

.PHONY: clean
clean:
	rm -f *.o
	rm -f boot
	rm -f setup
	rm -f linux.img
